﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Kinect;

namespace TableTennis
{
    class TopDownBody : Sprite
    {
        ColorImagePoint[] thisSkel;
        public DepthImagePoint[] thisSkelDepth;

        Line rUpperArm, rForeArm,
            lUpperArm, lForeArm,
            rHand, lHand;

        Line[] torso;
        Texture2D head;

        public TopDownBody(ColorImagePoint[] thisSkelPoints, DepthImagePoint[] thisSkelDepthPoints, GraphicsDevice GraphicsDev, ContentManager contentM)
        {
            thisSkel = thisSkelPoints;
            thisSkelDepth = thisSkelDepthPoints;
            setLimbs(GraphicsDev, contentM);
        }

        public void setLimbs(GraphicsDevice GraphicsDev, ContentManager contentM)
        {
            if (thisSkel != null)
            {

                rUpperArm = new Line(GraphicsDev, 1f, Color.White,
                    new Vector2(thisSkel[(int)JointType.ShoulderRight].X, convertedDepth(JointType.ShoulderRight)), new Vector2(thisSkel[(int)JointType.ElbowRight].X, convertedDepth(JointType.ElbowRight)));
                
                //rForeArm = new Line(GraphicsDev, 1f, Color.White,
                //    thisSkel[(int)JointType.ElbowRight], thisSkel[(int)JointType.WristRight]);
                //lUpperArm = new Line(GraphicsDev, 1f, Color.White,
                //    thisSkel[(int)JointType.ShoulderLeft], thisSkel[(int)JointType.ElbowLeft]);
                //lForeArm = new Line(GraphicsDev, 1f, Color.White,
                //    thisSkel[(int)JointType.ElbowLeft], thisSkel[(int)JointType.WristLeft]);
                
                //torso = new Line[2];
                //torso[0] = new Line(GraphicsDev, 1f, Color.White,
                //    thisSkel[(int)JointType.ShoulderLeft], thisSkel[(int)JointType.ShoulderCenter]);
                //torso[1] = new Line(GraphicsDev, 1f, Color.White,
                //    thisSkel[(int)JointType.ShoulderCenter], thisSkel[(int)JointType.ShoulderRight]);
                
                //rHand = new Line(GraphicsDev, 30f, Color.HotPink,
                //    thisSkel[(int)JointType.WristRight], thisSkel[(int)JointType.HandRight]);
                //lHand = new Line(GraphicsDev, 30f, Color.HotPink,
                //    thisSkel[(int)JointType.WristLeft], thisSkel[(int)JointType.HandLeft]);
                
                //Texture = contentM.Load<Texture2D>("head");
            }
        }

        public void DrawBody(SpriteBatch spriteBatch)
        {
            rUpperArm.DrawLine(spriteBatch);
            //rForeArm.DrawLine(spriteBatch);
            //lUpperArm.DrawLine(spriteBatch);
            //lForeArm.DrawLine(spriteBatch);
            
            //foreach (Line l in torso)
            //    l.DrawLine(spriteBatch);

            //rHand.DrawLine(spriteBatch);
            //lHand.DrawLine(spriteBatch);
            
            //spriteBatch.Draw(Texture, new Vector2(thisSkel[(int)JointType.Head].X, thisSkel[(int)JointType.Head].Y) - new Vector2(20),
            //     new Rectangle(0, 0, Texture.Width, Texture.Height), Color.White,
            //     theta, Vector2.Zero, 1.0f, SpriteEffects.None, 0); 
        }

        public float convertedDepth(JointType t)
        {
            float depth = thisSkelDepth[(int)t].Depth;
            return ((depth - 900f) * 1 / 10) + 300f;
            
        }
    }
}
